package com.tony.mindhr.service;

import com.tony.mindhr.mapper.RoleMapper;
import com.tony.mindhr.model.Role;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Title: RoleService
 * @Auther: 皮蛋布丁
 * @Date: 2021/06/01/22:53
 * @Description: 权限组用户角色
 */
@Service
public class RoleService {

    @Autowired
    RoleMapper roleMapper;

    /**
    * @Description: getAllroles 获取所有用户角色
    * @Param: []
    * @return: java.util.List<com.tony.mindhr.model.Role>
    * @Author: 皮蛋布丁
    * @Date: 2021/6/1 22:56
    */
    public List<Role> getAllroles() {
        return roleMapper.getAllroles();
    }

    /**
    * @Description: addRole 添加角色
    * @Param: [role]
    * @return: int
    * @Author: 皮蛋布丁
    * @Date: 2021/6/4 22:21
    */
    public Integer addRole(Role role) {
        if (!role.getName().startsWith("ROLE_")) {
            role.setName("ROLE_" + role.getName());
        }
        return roleMapper.insert(role);
    }

    /**
    * @Description: deleteRoleById 根据角色id删除角色
    * @Param: [rid]
    * @return: java.lang.Integer
    * @Author: 皮蛋布丁
    * @Date: 2021/6/5 15:51
    */
    public Integer deleteRoleById(Integer rid) {
        return roleMapper.deleteByPrimaryKey(rid);
    }
}
